s = []
a = int(input('Введите четырёхзначное число: '))
a1 = str(a)
if len(a1) == 4:
    k = 0
    b = a1[0]
    k1 =0
    c = a1[1]
    k2 = 0
    d = a1[2]
    k3 = 0
    e = a1[3]
    k4 = 0
    f = a1[: 2]
    k5 = 0
    g = a1[2:]
    k6 = 0
    h = a1[1:3]
    k7 = 0
    p = a1[1:]
    k8 = 0
    j = a1[0:3]
    k9 = 0
    for i in range(2, a):
        if a % i == 0:
            k += 1
        else:
            k += 0
    if k == 0:
        s.append(a)
    else:
        s.append(0)
    for i in range(2, int(b)):
        if int(b) % i == 0:
            k1 += 1
        else:
            k1 += 0
    if k1 == 0:
        s.append(int(b))
    else:
        s.append(0)
    for i in range(2, int(c)):
        if int(c) % i == 0:
            k2 += 1
        else:
          k2 += 0
    if k2 == 0:
        s.append(int(c))
    else:
        s.append(0)
    for i in range(2, int(d)):
        if int(d) % i == 0:
            k3 += 1
        else:
            k3 += 0
    if k3 == 0:
        s.append(int(d))
    else:
        s.append(0)
    for i in range(2, int(e)):
        if int(e) % i == 0:
            k4 += 1
        else:
            k4 += 0
    if k4 == 0:
        s.append(int(e))
    else:
        s.append(0)
    for i in range(2, int(f)):
        if int(f) % i == 0:
            k5 += 1
        else:
            k5 += 0
    if k5 == 0:
        s.append(int(f))
    else:
        s.append(0)
    for i in range(2, int(g)):
        if int(g) % i == 0:
            k6 += 1
        else:
            k6 += 0
    if k6 == 0:
        s.append(int(g))
    else:
        s.append(0)
    for i in range(2, int(h)):
        if int(h) % i == 0:
            k7 += 1
        else:
            k7 += 0
    if k7 == 0:
        s.append(int(h))
    else:
        s.append(0)
    for i in range(2, int(p)):
        if int(p) % i == 0:
            k8 += 1
        else:
            k8 += 0
    if k8 == 0:
        s.append(int(p))
    else:
        s.append(0)
    for i in range(2, int(e)):
        if int(e) % i == 0:
            k4 += 1
        else:
            k4 += 0
    if k4 == 0:
        s.append(int(p))
    else:
        s.append(0)
    for i in range(2, int(j)):
        if int(j) % i == 0:
            k9 += 1
        else:
            k9 += 0
    if k9 == 0:
        s.append(int(j))
    else:
        s.append(0)
    if s[0] > s[1] and s[0] > s[2] and s[0] > s[3] and s[0] > s[4] and s[0] > s[5] and s[0] > s[6] and s[0] > s[7] and s[0] > s[8] and s[0] > s[9] and s[0] > s[10]:
        print(s[0])
    elif s[1] > s[0] and s[1] > s[2] and s[1] > s[3] and s[1] > s[4] and s[1] > s[5] and s[1] > s[6] and s[1] > s[7] and s[1] > s[8] and s[1] > s[9] and s[1] > s[10]:
        print(s[1])
    elif s[2] > s[0] and s[2] > s[1] and s[2] > s[3] and s[2] > s[4] and s[2] > s[5] and s[2] > s[6] and s[2] > s[7] and s[2] > s[8] and s[2] > s[9] and s[2] > s[10]:
        print(s[2])
    elif s[3] > s[0] and s[3] > s[1] and s[3] > s[2] and s[3] > s[4] and s[3] > s[5] and s[3] > s[6] and s[3] > s[7] and s[3] > s[8] and s[3] > s[9] and s[3] > s[10]:
        print(s[3])
    elif s[4] > s[0] and s[4] > s[1] and s[4] > s[3] and s[4] > s[2] and s[4] > s[5] and s[4] > s[6] and s[4] > s[7] and s[4] > s[8] and s[4] > s[9] and s[4] > s[10]:
        print(s[4])
    elif s[5] > s[0] and s[5] > s[1] and s[5] > s[3] and s[5] > s[4] and s[5] > s[2] and s[5] > s[6] and s[5] > s[7] and s[5] > s[8] and s[5] > s[9] and s[5] > s[10]:
        print(s[5])
    elif s[6] > s[0] and s[6] > s[1] and s[6] > s[3] and s[6] > s[4] and s[6] > s[5] and s[6] > s[2] and s[6] > s[7] and s[6] > s[8] and s[6] > s[9] and s[6] > s[10]:
        print(s[6])
    elif s[7] > s[0] and s[7] > s[1] and s[7] > s[3] and s[7] > s[4] and s[7] > s[5] and s[7] > s[6] and s[7] > s[2] and s[7] > s[8] and s[7] > s[9] and s[7] > s[10]:
        print(s[7])
    elif s[8] > s[0] and s[8] > s[1] and s[8] > s[8] and s[8] > s[4] and s[8] > s[5] and s[8] > s[6] and s[8] > s[7] and s[8] > s[2] and s[8] > s[9] and s[8] > s[10]:
        print(s[8])
    elif s[9] > s[0] and s[9] > s[1] and s[9] > s[3] and s[9] > s[4] and s[9] > s[5] and s[9] > s[6] and s[9] > s[7] and s[9] > s[8] and s[9] > s[2] and s[9] > s[10]:
        print(s[9])
    elif s[10] > s[0] and s[10] > s[1] and s[10] > s[3] and s[10] > s[4] and s[10] > s[5] and s[10] > s[6] and s[10] > s[7] and s[10] > s[10] and s[10] > s[9] and s[10] > s[2]:
        print(s[10])
    else:
        print(0)
else:
    print(0)